<?php
//$username = isset($_POST['username']) ? trim($_POST['username']) : '';
//if (empty($username)) {
//    echo '用户名必须填写'; exit;
//}
//$password = isset($_POST['password']) ? $_POST['password'] : '';
//
//if (mb_strlen($password) < 6 || mb_strlen($password) > 20) {
//    echo '密码的长度应该在6-20之间'; exit;
//}
//
//// 判断正确
//echo 'success';exit;

// 基于json ajax 类似于js中的对象，python中字典，类似于PHP的索引数组
/**
 * data.status
 * {
*       "status": 200 // 200 成功 400 错误 500 服务器错误 401 未授权
 *      "message": "message",
 *      "data"
 * }
 */

function response($status, $message, $data = []) {
    $result = compact('status', 'message', 'data');
    echo json_encode($result);exit;
}
$username = isset($_POST['username']) ? trim($_POST['username']) : '';
if (empty($username)) {
    response(400, '用户名必须填写aaaa');
}
$password = isset($_POST['password']) ? $_POST['password'] : '';

if (mb_strlen($password) < 6 || mb_strlen($password) > 20) {
    response(400, '密码的长度应该在6-20之间');
}

$pattern1 = '/\d/';
$pattern2 = '/[a-z]/';
$pattern3 = '/[A-Z]/';
$pattern4 = '/[!@#$]/';
if (!preg_match($pattern1, $password) || !preg_match($pattern2, $password) ||
    !preg_match($pattern3, $password) || !preg_match($pattern4, $password)) {
    $result = [
        'status' => 400,
        'message' => '密码必须包含……'
    ];
    echo json_encode($result); exit;
}
// 判断正确
response(200, '登录成功', ['user_id' => 1011, 'points' => 99]);




